﻿using WeatherStationSys.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using WeatherStationSys.Interface.Scheduler;

namespace Nimbus1._0Platform
{
    /// <summary>
    /// Nimbus1.0硬件平台闹钟
    /// </summary>
    public class Nimbus1_0AlarmClock: IAlarmClock
    {
        public static int TicCount = 0;

        /// <summary>
        /// 容器
        /// </summary>
        private static List<IClockListener> _container;

        /// <summary>
        /// Ctor
        /// </summary>
        public Nimbus1_0AlarmClock()
        {
            _container = new List<IClockListener>();
        }

        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="clockListener"></param>
        public void Register(IClockListener clockListener)
        {
            _container.Add(clockListener);
        }

        /// <summary>
        /// 开始调度
        /// 自己控制调度速率
        /// </summary>
        public void StartScheduler()
        {
            Task.Run(() =>
            {
                while (true)
                {
                    if (TicCount % 6 == 0)//1分钟
                    {
                        foreach (var item in _container)
                        {
                            item.Tic();
                        }
                    }
                    Thread.Sleep(10000);
                    TicCount++;
                }
            });
        }
    }
}
